﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LanCommunity
{
    /// <summary>
    /// Rozszerzenia kontrolek
    /// </summary>
    public static class ControlsEx
    {
        /// <summary>
        /// Synchronizacja między wątkami
        /// </summary>
        /// <param name="form">aktualna formatka</param>
        /// <param name="method">metoda do wykonania</param>
        public static void Invoke(this Form form, MethodInvoker method)
        {
            if (form.Disposing)
                return;

            if (form.InvokeRequired)
                form.Invoke(method);
            else
                method();
        }

        /// <summary>
        /// Pokazuje wiadomość na pasku stanu
        /// </summary>
        /// <param name="statusLabel"></param>
        /// <param name="message"></param>
        public static void ShowStatusMessage(this ToolStripStatusLabel statusLabel, string message)
        {
            Form parent = statusLabel.GetCurrentParent().Parent as Form;
            parent.Invoke(() =>
                {
                    statusLabel.Text = message;
                });
        }
    }
}
